package payroll.trans;

import payroll.Employee;
import payroll.PayrollDatabase;
import payroll.classfication.CommissionedClassification;
import payroll.classfication.NotCommissionedClassificationEmployeeException;
import payroll.classfication.PaymentClassfication;
import payroll.classfication.SalesReceipt;
import payroll.exception.NoSuchEmployeeException;


public class SalesReceiptTransaction implements Transaction {

    private int empId;
    private String date;
    private double amount;

    public SalesReceiptTransaction(int empId, String date, double amount) {
        this.empId = empId;
        this.date = date;
        this.amount = amount;
       
    }

    @Override
    public void execute() {
        Employee e = PayrollDatabase.getEmployee(empId);
        if (e == null) {
            throw new NoSuchEmployeeException();
        }
        PaymentClassfication pc = e.getPaymentClassification();

        if (pc instanceof CommissionedClassification) {
            CommissionedClassification cc = (CommissionedClassification) pc;
            SalesReceipt sr = new SalesReceipt(date, amount);
            cc.addSalesReceipt(sr);
            
        }else{
            throw new NotCommissionedClassificationEmployeeException();
        }
        CommissionedClassification cc = (CommissionedClassification) pc;
        SalesReceipt sr = new SalesReceipt(date, amount);
        cc.addSalesReceipt(sr);

    }

}
